package cn.sciento.farm.devicemanager.service.impl;

import cn.sciento.farm.devicemanager.dao.entity.DevStrategy;
import cn.sciento.farm.devicemanager.dao.mapper.StrategyMapper;
import cn.sciento.farm.devicemanager.dao.model.StrategyInfo;
import cn.sciento.farm.devicemanager.sensor.Strategy;
import cn.sciento.farm.devicemanager.service.StrategyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements StrategyService {

    @Autowired
    StrategyMapper strategyMapper;

    @Override
    public int insert(DevStrategy devStrategy) {
        return strategyMapper.insert(devStrategy);
    }

    @Override
    public int updateById(DevStrategy devStrategy) {
        return strategyMapper.updateById(devStrategy);
    }

    @Override
    public int deleteById(long id) {
        return strategyMapper.deleteById(id);
    }

    @Override
    public List<StrategyInfo> getByControllerId(long controllerId) {
        List<StrategyInfo> strategies = strategyMapper.getByControllerId(controllerId);
        return strategies;
    }

    @Override
    public DevStrategy getById(long id) {
        return strategyMapper.selectById(id);
    }

    @Override
    public List<DevStrategy> getByCollectionId(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper<DevStrategy>();
        queryWrapper.eq("collection_id",id);
        List<DevStrategy> strategies = strategyMapper.selectList(queryWrapper);
        return strategies;
    }
}
